/*
 * @Descripttion: 
 * @version: 
 * @@Company: DCIT-SH
 * @Author: 王富银
 * @Date: 2024-08-08 14:02:14
 * @LastEditors: Sunny Chen
 * @LastEditTime: 2024-08-21 17:57:10
 */
import { createRouter, createWebHistory } from 'vue-router'
import { ElMessage} from 'element-plus'
import HomeMapView from '/src/views/HomeMapView.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    //车辆查询
    {
      path: '/query-cars',
      name: 'query-cars',
      component: () => import('@/views/QueryCarsView.vue')
    },
    //预取管理
    {
      path:"/region-management",
      name:"region-management",
      component: () => import('@/views/RegionManagement.vue')
    },
    //车辆投放
    {
      path:"/vehicle-deployment",
      name:"vehicle-deployment",
      component: () => import('@/views/VehicleDeployment.vue')
    },
    //轨迹查询
    {
      path:"/query-trajectory",
      name:"query-trajectory",
      component: () => import('@/views/QueryTrajectory.vue')
    },
    {
      path:"/task-center",
      name:"task-center",
      component: () => import('@/views/TaskCenterView.vue')
    },
    {
      path:"/data-center",
      name:"data-center",
      component:() => import("@/views/DataCenterView.vue")
    },
    {
      path:"/",
      name:"home",
      component:HomeMapView,
    },
    {
      path:"/login",
      name:"home",
      component:() => import("@/views/Login.vue")
    },
  ]
})

//全局导航守卫
router.beforeEach((to,from,next)=>{
  //获取登录的token
  const token = sessionStorage.getItem('token');
  if(token){
    next();
  }else{
    if(to.path !== '/login'){
      ElMessage({message:"请先登录",type:"info"});
      next('/login');
    }else{
      next();
    }
  }
})
export default router
